﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Ebooom.Leads.Business.AuthorRole;
using System.Web.Configuration;
using Achievement.Common;

namespace Achievement.Web.Common
{
    [AttributeUsage(AttributeTargets.All)]
    public class AuthorizeFilterAttribute : FilterAttribute, IAuthorizationFilter
    {
        public long ValidataRole
        {
            get;
            set;
        }
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            if (UserInfo.CurrentUser == null || !AuthorRoleUtils.IsHasRight(UserInfo.CurrentUser.Roles.SecureToLong(), ValidataRole))
            {
                filterContext.Result = new RedirectResult(WebConfigurationManager.AppSettings["ErrorPage"]);
            }
        }
    }
}